<template>
    <div class="loanApply">
        <el-breadcrumb class="breadcrumb" separator="/">
            <el-breadcrumb-item :to="{ path: '/order' }">我的订单</el-breadcrumb-item>
            <el-breadcrumb-item>贷款申请</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="order-content">
            <label class="filterText">关键字</label>
            <el-input class="order-input-filter" placeholder="请输入姓名/身份证号/手机号码/订单号" v-model="filter.text" icon="circle-cross" :on-icon-click="deleFilterText">
            </el-input>
            <label class="filterText">申请日期</label>
            <el-date-picker v-model="filter.time" type="daterange" placeholder="选择日期">
            </el-date-picker>
            <el-button class="filter-button-search" type="primary" icon="search" @click="search">搜索</el-button>
            <el-table class="order-table" :data="tableData" style="width: 100%" empty-text="暂无搜索结果" @filter-change="filterChange">
                <el-table-column prop="orderNo" label="订单编号" width="200">
                </el-table-column>
                <el-table-column prop="name" label="姓名" width="100">
                </el-table-column>
                <el-table-column prop="code" label="身份证号" width="200">
                </el-table-column>
                <el-table-column prop="type" label="车型" width="180">
                </el-table-column>
                <el-table-column prop="bank" label="贷款银行" :filters="$store.state.bank" filter-placement="bottom-end" width="120">
                </el-table-column>
                <el-table-column prop="money" label="贷款金额" width="100">
                </el-table-column>
                <el-table-column prop="phone" label="联系电话" width="130">
                </el-table-column>
                <el-table-column prop="status" label="状态" :filters="$store.state.orderStatusLoan" filter-placement="bottom-end" width="180">
                    <template scope="scope">
                        <el-tag v-if="scope.row.status == '征信结果待录入' || scope.row.status == '征信结果已录入'||scope.row.status == '修改征信结果待录入' || scope.row.status == '修改征信结果已录入'|| scope.row.status == '审核中'|| scope.row.status == '垫款审核中'" :type="'primary'">{{scope.row.status}}</el-tag>
                        <el-tag v-else-if="scope.row.status == '已结清' || scope.row.status == '贷款申请通过' || scope.row.status == '财务已垫款' || scope.row.status == '银行已放款'" :type="'success'">{{scope.row.status}}</el-tag>
                        <el-tag v-else-if="scope.row.status == '贷款审核未通过'||scope.row.status == '垫款驳回'" :type="'danger'">{{scope.row.status}}</el-tag>
                        <el-tag v-else-if="scope.row.status == '已作废'||scope.row.status == '已撤回'" :type="'gray'">{{scope.row.status}}</el-tag>
                        <el-tag v-else>{{scope.row.status}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="time" label="申请时间" sortable min-width="180">
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="80">
                    <template scope="scope">
                        <el-button type="text" size="small">
                            <router-link :to="{path:'/loanApplyDeal?orderNo='+scope.row.orderNo + '&annexBatchNo='+scope.row.annexBatchNo+'&customerIdCard='+scope.row.code+'&orderStatus='+scope.row.orderStatus}">查看</router-link>
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="order-pagination">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="tablePage.page" :page-sizes="[10, 20, 30, 40]" :page-size="tablePage.num" layout="sizes, prev, pager, next" :page-count="tablePage.pager">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    name: 'loanApply',
    components: {},
    data() {
        return {
            filter: {
                time: [],
                text: '',
                bank: '',
                status: '',
                bankList: [],
                statusList: [],
            },
            tableData: [],
            tablePage: {
                pager: 1, //总页数
                page: 1, //当前页数
                num: 10, //每页条数
            },
        }
    },
    methods: {
        filterChange(data) {
            for (let i in data) {
                switch (i) {
                    case 'status':
                        this.filter.status = data[i][data[i].length - 1];
                        this.filter.statusList = data[i];
                        break;
                    case 'bank':
                        this.filter.bank = data[i][data[i].length - 1];
                        this.filter.bankList = data[i];
                        break;
                }
            }

            this.search();
        },
        info(index, rows) {
            console.log(rows);
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.tablePage.num = val;
            this.search();
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.tablePage.page = val;
            this.search();
        },
        deleFilterText() {
            this.filter.text = '';
        },
        search() {
            let param = {
                gmtCreateBegin: this.filter.time[0] ? this.$libs.formatDate(this.filter.time[0], 'yyyy-MM-dd') : '',
                gmtCreateEnd: this.filter.time[1] ? this.$libs.formatDate(this.filter.time[1], 'yyyy-MM-dd') : '',
                keyword: this.filter.text,
                orderStatus: this.filter.statusList.length > 1 ? '' : this.filter.status,
                orderStatusList: 10 + '%2C' + 11 + '%2C' + 12 + '%2C' + 13,
                loanBankId: this.filter.bankList.length > 1 ? '' : this.filter.bank,
                loanBankIdList: this.filter.bankList.length > 1 ? this.filter.bankList.join('%2C') : '',
                pageNO: this.tablePage.page,
                pageSize: this.tablePage.num
            };
            console.log('param');
            console.log(param);
            this.tableData = [];
            this.$http.get(this.$libs.getUrlSplit("/order/orders", param)).then((response) => {
                console.log(response);
                if (response.data.success) {
                    console.log(response.data.result);
                    let that = this;
                    that.tablePage.pager = parseInt(response.data.data.totalPage);
                    that.tablePage.num = parseInt(response.data.data.pageSize);
                    console.log(that.tablePage);
                    this.tableData = [];
                    $.each(response.data.data.result, function(index, el) {
                        that.tableData.push({
                            name: el.customerName,
                            code: el.customerIdCard,
                            type: el.carModel,
                            bank: el.loanBankName,
                            money: el.loanAmount,
                            phone: el.mobilePhone,
                            status: el.orderStatusDesc,
                            time: el.gmtCreate,
                            orderNo: el.orderNo,
                            annexBatchNo: el.annexBatchNo,
                            customerId: el.customerId,
                            orderStatus: el.orderStatus,
                            applyId: el.applyId,
                            commonCustomerName: el.commonCustomerName,
                            commonCustomerIdCard: el.commonCustomerIdCard
                        })
                    });
                }
            }).catch((error) => {});

        },
    },
    mounted() {
        this.search();
        this.$store.commit('bank', this);
        this.$store.commit('orderStatusLoan', this);
    }
}

</script>
<style lang="scss" scoped>
@import '../../assets/css/site.scss';
.loanApply {
    padding: 10px 16px;
    .title {
        color: #99A9BF;
        font-size: 14px;
        line-height: 18px;
        margin: 8px 0px 10px 0px;
    }
    .order-content {
        background: #fff;
        padding: 20px;
        overflow: auto;
        position: absolute;
        bottom: 20px;
        left: 20px;
        right: 20px;
        top: 45px;
        .filterText {
            font-size: 14px;
            color: #475669;
            margin: 0px 5px 0px 15px;
        }
        .order-hr {
            margin: 20px 0px 30px 0px;
            background: #D3DCE6;
        }
        .order-input-filter {
            width: 285px;
        }
        .filter-button-search {
            margin-left: 30px;
        }
        .order-table {
            margin: 20px 0px;
        }
        .order-pagination {
            text-align: center;
        }
        a {
            color: #20a0ff;
        }
    }
}

</style>
